<?php

require 'lib/model/om/BaseColoanaPeer.php';

class ColoanaPeer extends BaseColoanaPeer
{
    /**
     * Retrieves a single object by primary key for the current user
     *
     * @param int $key
     * @return Coloana
     */
    public static function find($key)
    {
        $criteria = new Criteria();

        // o coloana poate fi generala sau sa fie definita de userul curent
        $c1 = $criteria->getNewCriterion(self::USER_ID, sfContext::getInstance()->getUser()->getId());
        $c2 = $criteria->getNewCriterion(self::USER_ID, null, Criteria::ISNULL);
        $userCriterion = $c1->addOr($c2);

        $criteria
            ->add(self::ID, $key)
            ->add($userCriterion);

        $c = $criteria->toString();

        $coloana = self::doSelectOne($criteria);

        return $coloana;
    }

}
